<?php


class merchantModule extends Module {

    /*
     * 在构造函数中装载所依赖的类或其他文件
    */
    function __construct() {
        $this->includePhp('merchant', 'merchant');
    }
    /*
     * 激活创建数据库
    */
//    public function activate() {
//        Module::importSQL (module_sql_path('mass'));
//    }

    /*
     * 调用插件资源
    */
    public function call($user, $method, $param) {
        switch ($method) {
            case 'index':
                merchant::index();
                break;
            case 'addMivendorByReg':
                $name = $param->name;
                $companyName = $param->companyName;
                $phone = $param->phone;
                $province = $param->province;
                $city = $param->city;
                $areaCode = $param->areaCode;
                if (!$name || !$companyName || !$phone||!$province||!$city) {
                    Output::instance()->resultCode(code_lackof_param);
                    return;
                }
                merchant::addMivendorByReg($name,$companyName,$phone,$province,$city,$areaCode);
                break;
            case 'storeIndex':
                merchant::storeIndex();
                break;
            case 'getStoreList':
                $vid = $param->vid;
                $start = $param->start;
                $limit = $param->limit;
                if (!$vid) {
                    Output::instance()->resultCode(code_lackof_param);
                    return;
                }
                merchant::getStoreList($vid,$start,$limit);
                break;
            case 'getStoreById':
                $id = $param->id;
                merchant::getStoreById($id);
                break;
            case 'saveStore':
                $name = $param->name;
                $phone = $param->phone;
                $address = $param->address;
                $picUrl1 = $param->picUrl;
                $vid = $param->vid;
                $province = $param->province;
                $city = $param->city;
                $country = $param->area;
                $service = $param->service;
                $longitude = $param->lng;
                $latitude = $param->lat;
                $id = $param->id;
                if (!$vid) {
                    Output::instance()->resultCode(code_lackof_param);
                    return;
                }
                merchant::saveStore($name,$phone,$address,$picUrl1,$vid,$province,$city,$country,$service,$id,$longitude,$latitude);
                break;
            case 'getVerification':
                $id = $param->id;
                $again = $param->again;
                if (!$id) {
                    Output::instance()->resultCode(code_lackof_param);
                    return;
                }
                merchant::getVerification($id,$again);
                break;
            case 'saveVerification':
                $id = $param->id;
                $busLicence = $param->busLicence;
                $IDPositive = $param->IDPositive;
                $IDBack = $param->IDBack;
                $certificationType = $param->certificationType;
                $wxid = $param->wxid;
                $phone = $param->phone;
                if (!$id||!$IDBack||!$IDPositive) {
                    Output::instance()->resultCode(code_lackof_param);
                    return;
                }
                merchant::saveVerification($id,$busLicence,$IDPositive,$IDBack,$certificationType,$wxid,$phone);
                break;
            case 'setVendorStatus':
                $id = $param->id;
                if (!$id) {
                    Output::instance()->resultCode(code_lackof_param);
                    return;
                }
                merchant::setVendorStatus($id);
                break;

            case 'getCertificate':
                merchant::getCertificate();
                break;
            case 'deletedStore':
                $id = $param->id;
                if(!$id){
                    Output::instance()->resultCode(code_lackof_param);
                    return;
                }
                merchant::deletedStore($id);
                break;
            case "resetIdentifice":
                $id = $param->id;
                merchant::resetIdentifice($id);
                break;
            case "vendorActivate":
                $id = $param->id;
                merchant::vendorActivate($id);
                break;
            case "getVendorInfo":
                $id = $param->id;
                merchant::getVendorInfo($id);
                break;
            case "saveVendorInfo":
                $id = $param->id;
                $name = $param->name;
                $phone = $param->phone;
                if (!$id||!$name||!$phone) {
                    Output::instance()->resultCode(code_lackof_param);
                    return;
                }
                merchant::saveVendorInfo($id,$name,$phone);
                break;
        }
    }
}


$module = new merchantModule();
Module::addModule($module);